package com.ruoyi.train.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.firefighter.domain.FirefighterInfo;
import com.ruoyi.firefighter.service.IFirefighterInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.train.mapper.FirefighterTrainMapper;
import com.ruoyi.train.domain.FirefighterTrain;
import com.ruoyi.train.service.IFirefighterTrainService;

/**
 * 培训经历Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Service
public class FirefighterTrainServiceImpl implements IFirefighterTrainService
{
    @Autowired
    private FirefighterTrainMapper firefighterTrainMapper;
    @Autowired
    private IFirefighterInfoService iFirefighterInfoService;
    /**
     * 查询培训经历
     *
     * @param id 培训经历主键
     * @return 培训经历
     */
    @Override
    public FirefighterTrain selectFirefighterTrainById(Long id)
    {
        return firefighterTrainMapper.selectFirefighterTrainById(id);
    }

    /**
     * 查询培训经历列表
     *
     * @param firefighterTrain 培训经历
     * @return 培训经历
     */
    @Override
    public List<FirefighterTrain> selectFirefighterTrainList(FirefighterTrain firefighterTrain)
    {
        return firefighterTrainMapper.selectFirefighterTrainList(firefighterTrain);
    }

    /**
     * 新增培训经历
     *
     * @param firefighterTrain 培训经历
     * @return 结果
     */
    @Override
    public int insertFirefighterTrain(FirefighterTrain firefighterTrain)
    {
        FirefighterInfo firefighterInfo1 = new FirefighterInfo();
        firefighterInfo1.setIdCardNumber(firefighterTrain.getFirefighterIdCard());
        FirefighterInfo firefighterInfo= iFirefighterInfoService.selectFirefighterInfoBySfz(firefighterInfo1);
        if (firefighterInfo==null){
            return 0;
        }
        firefighterTrain.setFirefighterId(firefighterInfo.getUserId());
        firefighterTrain.setCreateTime(DateUtils.getNowDate());
        return firefighterTrainMapper.insertFirefighterTrain(firefighterTrain);
    }

    /**
     * 修改培训经历
     *
     * @param firefighterTrain 培训经历
     * @return 结果
     */
    @Override
    public int updateFirefighterTrain(FirefighterTrain firefighterTrain)
    {
        firefighterTrain.setUpdateTime(DateUtils.getNowDate());
        return firefighterTrainMapper.updateFirefighterTrain(firefighterTrain);
    }

    /**
     * 批量删除培训经历
     *
     * @param ids 需要删除的培训经历主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterTrainByIds(Long[] ids)
    {
        return firefighterTrainMapper.deleteFirefighterTrainByIds(ids);
    }

    /**
     * 删除培训经历信息
     *
     * @param id 培训经历主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterTrainById(Long id)
    {
        return firefighterTrainMapper.deleteFirefighterTrainById(id);
    }

    @Override
    public void deleteFirefighterTrainById1(Long userId) {
         firefighterTrainMapper.deleteFirefighterTrainByIduser(userId);
    }
}
